package com.dong.springshell.hello;

import com.dong.springshell.service.TestService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.ShellOption;

@RequiredArgsConstructor
@Slf4j
@ShellComponent
public class HelloCommands {

    @Value("${spring.application.name}")
    private String appName;

    private final TestService testService;

    /**
     * hello --name "xxxxxx"
     *
     * @param name
     * @return
     */
    @ShellMethod(key = "hello")
    public String hello(@ShellOption(defaultValue = "dongxiao") String name) {
        log.info("appName = " + appName);
        return "Hello " + name + "!";
    }

    @ShellMethod(key = "test")
    public void testJdbcTemplate() {
        testService.testJdbcTemplate();
    }

}
